package morenoapp.components.thinktable;

import java.awt.Point;
import java.awt.event.MouseEvent;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import morenoapp.components.common.table.column.MatrixTableColumnModel;
import morenoapp.components.common.table.renderer.StyledTableValue;
import morenoapp.components.common.table.renderer.StyledValueTableCellRenderer;

/**
 *
 * @author dmitry.mamonov
 */
public class ThinktableTableJPanel extends javax.swing.JPanel {
    ThinktableTableModel thinktableTableModel = new ThinktableTableModel();

    /** Creates new form ThinktableTableJScrollPane */
    public ThinktableTableJPanel() {
        initComponents();

        MatrixTableColumnModel matrixTableColumnModel = new MatrixTableColumnModel(thinktableTableModel);
        jTable.setDefaultRenderer(StyledTableValue.class, new StyledValueTableCellRenderer());
        jTable.setColumnModel(matrixTableColumnModel);
        jTable.setModel(thinktableTableModel);
        jTable.setColumnSelectionAllowed(true);
        jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        jTable.setFont(jTable.getFont().deriveFont(8));
        //jTable.setRowHeight(10);
        //jScrollPane.setRowHeaderView(new RowHeaderRenderer(jTable));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane = new javax.swing.JScrollPane();
        jTable = createTable();

        setName("Form"); // NOI18N

        jScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane.setName("jScrollPane"); // NOI18N

        jTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "NOI18N", "NOI18N", "NOI18N", "NOI18N"
            }
        ));
        jTable.setName("jTable"); // NOI18N
        jScrollPane.setViewportView(jTable);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane;
    private javax.swing.JTable jTable;
    // End of variables declaration//GEN-END:variables

    public ThinktableTableModel getThinktableTableModel() {
        return thinktableTableModel;
    }

    public JTable getJTable() {
        return jTable;
    }

    public JTable createTable() {
        return new JTable() {
            @Override
            protected JTableHeader createDefaultTableHeader() {
                return new JTableHeader(columnModel) {
                    @Override
                    public String getToolTipText(MouseEvent event) {
                        Point p = event.getPoint();
                        int column = columnAtPoint(p);
                        if (column != -1) {
                            String tip = getThinktableTableModel().getColumnMeta(column).getTooltip();
                            return tip;
                        } else {
                            return null;
                        }
                    }
                };
            }
        };
    }
}
